/*******************************************************************************
 * Simple C-K Editor
 * 
 * Copyright (C) 2009 Ingi BROWN - Centre de Gestion Scientifique - Ecole des Mines ParisTech
 * Licensed under the GNU General Public License Version 3.
 * 
 * Simple C-K Editor includes source code and libraries from the JUNG Project (Java Universal Network/Graph Framework) 
 * released under the BSD license. Copyright (c) 2003-2004,  Regents of the University of California and the JUNG Project.
 * 
 * See the License.txt file for more details.
 ******************************************************************************/

/*
 * MyMouseMenus.java
 *
 * Created on March 21, 2007, 3:34 PM; Updated May 29, 2007
 *
 * Copyright March 21, 2007 Grotto Networking
 *
 */

package edu.ensmp.ckEditor.mousePlugin;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Point2D;

import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;


import edu.ensmp.ckEditor.ckModel.CKModel.Concept;
import edu.ensmp.ckEditor.ckModel.CKModel.Knowledge;
import edu.uci.ics.jung.visualization.VisualizationViewer;

/**
 * A collection of classes used to assemble popup mouse menus for the custom
 * edges and vertices developed in this example.
 * 
 * @author Dr. Greg M. Bernstein
 * @author Modified by Ingi BROWN (09/2009)
 */
public class MyMouseMenus {

	public static class EdgeMenu extends JPopupMenu {
		// private JFrame frame;
		public EdgeMenu(final JFrame frame) {
			super("Edge Menu");
			// this.frame = frame;
			this.add(new DeleteEdgeMenuItem());
		}

	}

	public static class ConceptMenu extends JPopupMenu {
		public ConceptMenu(final JFrame frame) {
			super("Vertex Menu");
			this.add(new DeleteVertexMenuItem<Concept>());
			this.addSeparator();
			this.add(new ConceptPropertiesItem(frame));
		}
	}

	public static class ConceptPropertiesItem extends JMenuItem implements
			VertexMenuListener<Concept>, MenuPointListener {
		Concept concept;
		VisualizationViewer visComp;
		Point2D point;

		public void setVertexAndView(Concept concept,
				VisualizationViewer visComp) {
			this.concept = concept;
			this.visComp = visComp;
		}

		public void setPoint(Point2D point) {
			this.point = point;
		}

		public ConceptPropertiesItem(final JFrame frame) {
			super("Edit Concept Properties...");
			this.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					VertexPropertyDialog dialog = new VertexPropertyDialog(
							frame, concept);
					dialog.setLocation((int) point.getX() + frame.getX(),
							(int) point.getY() + frame.getY());
					dialog.setVisible(true);
				}

			});
		}

	}

	public static class KnowledgeMenu extends JPopupMenu {
		public KnowledgeMenu(final JFrame frame) {
			super("Vertex Menu");
			this.add(new DeleteVertexMenuItem<Knowledge>());
			this.addSeparator();
			this.add(new KnowledgePropertiesItem(frame));
		}
	}

	public static class KnowledgePropertiesItem extends JMenuItem implements
			VertexMenuListener<Knowledge>, MenuPointListener {
		Knowledge knowledge;
		VisualizationViewer visComp;
		Point2D point;

		public void setVertexAndView(Knowledge knowledge,
				VisualizationViewer visComp) {
			this.knowledge = knowledge;
			this.visComp = visComp;
		}

		public void setPoint(Point2D point) {
			this.point = point;
		}

		public KnowledgePropertiesItem(final JFrame frame) {
			super("Edit Knowledge Properties...");
			this.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					VertexPropertyDialog dialog = new VertexPropertyDialog(
							frame, knowledge);
					dialog.setLocation((int) point.getX() + frame.getX(),
							(int) point.getY() + frame.getY());
					dialog.setVisible(true);
				}

			});
		}

	}

}
